package com.xh.login.controller;

import com.xh.login.entity.User;
import com.xh.login.service.UserService;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author mucd
 * @date 2022/3/20 2022/3/20
 */
@RestController
public class TestRedisController {

    @Resource
    private RedisTemplate<String, List<User>> redisTemplate;

    @Resource
    private UserService userService;


    @RequestMapping("/saveList")
    public Object saveList(){
        ListOperations<String, List<User>> listOperations = redisTemplate.opsForList();
        List<User> userList = new ArrayList<>();

        //如果User实体类不序列化就会报错
        List<User> index = userService.index();

        Long list = listOperations.leftPush("list", index);

        System.out.println("list = " + list);

        return index;
    }

}
